package ahblue.cn.tanzi.ui.person;

import android.content.ClipData;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import ahblue.cn.tanzi.R;
import ahblue.cn.tanzi.data.source.ApiCallback;
import ahblue.cn.tanzi.data.source.RemoteRepository;
import ahblue.cn.tanzi.jmessage.im.util.ToastUtil;
import ahblue.cn.tanzi.model.user.CodeModel;
import ahblue.cn.tanzi.model.user.LoginResultModel;
import ahblue.cn.tanzi.ui.base.BaseActivity;
import ahblue.cn.tanzi.util.ImageLoadUtil;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by fengdongfei on 2018/12/1.
 */

public class ShareLinkActivity extends BaseActivity {
    @BindView(R.id.ivimg)
    ImageView ivimg;
    @BindView(R.id.bt_copy_share_link)
    Button btCopyShareLink;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sharelink);
        ButterKnife.bind(this);

        CodeModel.ShareLink(this,LoginResultModel.getToken(this),new CodeModel.DataVertifyListener(){

            @Override
            public void conver(String orderSn) {
                ImageLoadUtil.load(ShareLinkActivity.this,orderSn,ivimg);
            }
        });

    }

    @OnClick({R.id.btn_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_back:
                finish();
                break;

        }
    }

    @OnClick({R.id.bt_copy_share_link})
    public void onBtShareLinkClicked(View view){
        RemoteRepository repo = RemoteRepository.getsInstance();
        repo.getShareLink(LoginResultModel.getToken(this),mGetShareLinkCallback);
    }

    private ApiCallback<String> mGetShareLinkCallback = new ApiCallback<String>() {


        @Override
        public void onSuccess(String data) {
            android.content.ClipboardManager c = (android.content.ClipboardManager) ShareLinkActivity.this.getSystemService(CLIPBOARD_SERVICE);
            c.setPrimaryClip(ClipData.newPlainText("dpy",data ));
            ToastUtil.shortToast(ShareLinkActivity.this,"分享链接已复制");
        }

        @Override
        public void onFailed(String errorMsg) {

        }
    };
}
